
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;


public class Server implements Runnable{
	public static String message = null;
   DatagramSocket theSocket = null;
   
   public Server () {      
      
      try {
         theSocket = new DatagramSocket(1235);
         //System.out.println("Server created and waiting for incomming connections...");
      } catch (SocketException e) {
         // TODO Auto-generated catch block
         System.out.println("Error creating the socket: " + e.getMessage());
      }
   }
   
   public void run() {
      
      DatagramPacket theRecievedPacket;
      byte[] inBuffer;    
      
      try {
         while(true){
        	 //message = "?filme:Stranger Than Fiction.avi";
            // create some space for the text to send and recieve data
            inBuffer = new byte[500];
            
            // create a place for the client to send data too
            theRecievedPacket = new DatagramPacket(inBuffer, inBuffer.length);
            // wait for a client to request a connection
            theSocket.receive(theRecievedPacket); 
            
            message = new String(theRecievedPacket.getData(),0, theRecievedPacket.getLength());
            //Exemplo1.label.setText(message);
            System.out.println(message);
         }
      } catch (IOException ExceIO){
         System.out.println("Error with client request : "+ExceIO.getMessage());
      }
      
      // close the server socket
   }
}
